package com.xinsilu.hospital.service.impl;

import com.xinsilu.hospital.entity.AuthsysMenu;
import com.xinsilu.hospital.entity.AuthsysUser;
import com.xinsilu.hospital.service.IAuthService;
import com.xinsilu.hospital.service.IAuthsysMenuService;
import com.xinsilu.hospital.service.IAuthsysUserService;
import com.xinsilu.utils.EncryptUtil;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

public class IAuthServiceImpl implements IAuthService {

    @Autowired
    private IAuthsysMenuService menuService;

    @Autowired
    private IAuthsysUserService userService;
    @Override
    public List<AuthsysMenu> getMenus() {
        return this.menuService.findFirstMenus();
    }

    @Override
    public AuthsysUser verify(String username, String password) {
        AuthsysUser user = this.userService.findByUserName(username);
        if(user == null){
            throw new RuntimeException(username + "不存在");
        }else{
            password = EncryptUtil.getMD5Str(password);
            if(password.equals(user.getUrPassword())){
                return user;
            }
        }
        return null;
    }

}
